// Business system types definition

import type { TemplateTable, AssessmentType as TemplateAssessmentType } from './template';

// 保持向后兼容，同时导出模板中的类型
export type AssessmentType = '101' | '102' | '103' | '104' | '105'; // 101: 双新评估, 102: 涉诈评估, 103: 智慧中台评估,104: 5G应用安全评估, 105: 数据安全评估
export type AssessmentStatus = 'in_progress' | 'completed';

/**
 * Business system represents an assessment plan in the application
 */
export interface BusinessSystem {
  id: string;
  name: string;
  ratingFilingName: string; // 定级备案名称
  responsiblePerson: string; // 责任人
  businessDepartment: string; // 业务负责人部门
  contact: string; // 联系方式
  assessmentType: AssessmentType; // 评估类型
  templateID: string; // 模板ID
  expectedCompletionDate: string; // 预计完成时间 (YYYY-MM-DD format)
  createdAt: string; // 创建时间 (YYYY-MM-DD format)
  status: AssessmentStatus; // 进度状态
}

/**
 * Statistics about business systems
 */
export interface BusinessStatistics {
  total: number; // Total number of assessment plans
  inProgress: number; // Number of in-progress assessments
  completed: number; // Number of completed assessments
}

/**
 * Parameters for creating a new business system
 */
export type CreateBusinessSystem = Omit<BusinessSystem, 'id' | 'createdAt' | 'status'>;

/**
 * Parameters for updating an existing business system
 */
export type UpdateBusinessSystem = Partial<Omit<BusinessSystem, 'id' | 'createdAt'>>;

/**
 * Context type for business systems management
 */
export interface BusinessContextType {
  // Data
  businessSystems: BusinessSystem[]; // List of all business systems
  statistics: BusinessStatistics; // Statistics about business systems
  selectedBusiness: BusinessSystem | null; // Currently selected business system
  
  // Loading and error states
  isLoading: boolean; // Whether an operation is in progress
  error: Error | null; // Last error that occurred
  
  // Actions
  setSelectedBusiness: (business: BusinessSystem | null) => void; // Set the selected business system
  
  /**
   * Add a new business system
   * @param businessSystem Business system data without ID and timestamps
   * @returns Promise that resolves with the created business system
   */
  addBusinessSystem: (businessSystem: CreateBusinessSystem) => Promise<BusinessSystem>;
  
  /**
   * Update an existing business system
   * @param id ID of the business system to update
   * @param updates Partial updates to apply
   */
  updateBusinessSystem: (id: string, updates: UpdateBusinessSystem) => Promise<void>;
  
  /**
   * Delete a business system
   * @param id ID of the business system to delete
   */
  deleteBusinessSystem: (id: string) => Promise<void>;
  
  /**
   * Search business systems by name or responsible person
   * @param keyword Search keyword
   * @returns Promise that resolves with matching business systems
   */
  searchBusinessSystems: (keyword: string) => Promise<BusinessSystem[]>;
  
  /**
   * Filter business systems by status and/or type
   * @param status Optional status filter
   * @param type Optional assessment type filter
   * @returns Promise that resolves with filtered business systems
   */
  filterBusinessSystems: (status?: AssessmentStatus, type?: AssessmentType) => Promise<BusinessSystem[]>;
  
  /**
   * Get the display name for an assessment type
   * @param type Assessment type code
   * @returns Localized display name
   */
  getAssessmentTypeName: (type: AssessmentType) => string;
  
  /**
   * 根据评估类型获取模板列表
   * @param assessmentType 评估类型
   * @returns Promise that resolves with template list
   */
  fetchTemplates: (assessmentType: TemplateAssessmentType) => Promise<TemplateTable[]>;
}
